package com.wzt.lianfirecontrol.fragment;

import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wzt.lianfirecontrol.App;
import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.activity.BaseActivity;
import com.wzt.lianfirecontrol.adapter.home.HomeStatisticAdapter;
import com.wzt.lianfirecontrol.adapter.home.system.baojing.DeviceErrorAdapter;
import com.wzt.lianfirecontrol.bean.ConstData;
import com.wzt.lianfirecontrol.bean.recode.ListModel;
import com.wzt.lianfirecontrol.bean.recode.home.ChartsModel;
import com.wzt.lianfirecontrol.bean.recode.home.ChartsModel2;
import com.wzt.lianfirecontrol.bean.recode.home.jiankong.JianKongDeviceModel;
import com.wzt.lianfirecontrol.bean.recode.home.system.baojing.DetailErrorModel;
import com.wzt.lianfirecontrol.bean.recode.home.system.baojing.DeviceChartItemModel;
import com.wzt.lianfirecontrol.bean.recode.home.system.baojing.DeviceChartModel;
import com.wzt.lianfirecontrol.bean.recode.home.system.baojing.SysBaoJingDeviceDetailModel;
import com.wzt.lianfirecontrol.bean.recode.user.UserInfoModel;
import com.wzt.lianfirecontrol.http.HttpHelper;
import com.wzt.lianfirecontrol.http.json.ParseJsonData;
import com.wzt.lianfirecontrol.http.Url;
import com.wzt.lianfirecontrol.utils.JSONUtil;
import com.wzt.lianfirecontrol.utils.SpUtils;
import com.wzt.lianfirecontrol.utils.StringUtils;
import com.wzt.lianfirecontrol.utils.Utils;
import com.wzt.lianfirecontrol.view.InitView;
import com.wzt.lianfirecontrol.view.SuperSwipeRefreshLayout;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import static androidx.constraintlayout.widget.ConstraintLayoutStates.TAG;

public class DeviceDetailFragment extends BaseFragment implements SuperSwipeRefreshLayout.OnSwipeRefreshListener {

    private BaseActivity activity;
    private Bundle bundle;
    private View itemContentView;

    private SuperSwipeRefreshLayout swipe_container;

    private LinearLayout ll_device_info;
    /**
     * 设备标题
     */
    private ImageView iv_device_img;
    private TextView tv_device_title;
    private TextView tv_device_flag;
    private TextView tv_device_flag_1;
    private ImageView iv_icon_video;
    /**
     * 设备位置
     */
    private ImageView iv_device_location;
    private TextView tv_device_location;
    /**
     * 设备信息
     */
    private TextView tv_device_id;
    private TextView tv_device_type;
    /**
     * 表格信息
     */
    private LinearLayout ll_data_chart;
    private ImageView iv_chart_img;
    private TextView tv_chart_title;
    private ImageView iv_data_time_img;
    private TextView tv_data_time;
    private RecyclerView rlv_chart_list;
    private LinearLayoutManager llm_chart;
    private HomeStatisticAdapter homeStatisticAdapter;
    /**
     * 报警历史
     */
    private LinearLayout ll_data_history;
    private RecyclerView rlv_history_list;
    private LinearLayoutManager linearLayoutManager;
    private DeviceErrorAdapter deviceErrorlAdapter;

    /**
     * 列表底部数据加载状态
     */
    private View footerView;
    private LinearLayout ll_recycler_footer;
    private RelativeLayout rl_no_more_data;

    private View include_no_data;
    private View include_no_net;
    private View include_progress_bar;

    private static final int BAOJING_DETAIL_REQUEST_WHAT = 0;
    private static final int JIANCE_DETAIL_REQUEST_WHAT = 1;
    private static final int YICHANG_DETAIL_REQUEST_WHAT = 2;
    private static final int GET_VIDEO_LIST_WHAT = 3;
    private int currentPage = 1;
    private boolean isNoMoreData = false;
    private boolean isListLoadOver = true;
    private int lastVisibleItem;

    private String equId;

    private SysBaoJingDeviceDetailModel detailHeadModel;
    private TextView mTvfault;
    private TextView mTv_fault_des;

    //  private TextView mTvFaultDes;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (null == itemContentView){
            bundle = getArguments();
            activity = getMyActivity();
            if (null != bundle){
                equId = bundle.getString("equId", "");

            }
            if (StringUtils.isEmpty(equId)){
                activity.finish();
            }
            itemContentView = inflater.inflate(R.layout.f_baojing_detail, container, false);
            initView();
            initHttpHelper();
        }
        if (itemContentView.getParent() != null) {
            ((ViewGroup) itemContentView.getParent()).removeView(itemContentView);
        }
        return itemContentView;
    }

    private void initView() {

     //   mTvFaultDes = (TextView) itemContentView.findViewById(R.id.tv_fault_des);
        swipe_container = itemContentView.findViewById(R.id.swipe_container);
        InitView.instance().initSuperSwipeLayout(swipe_container);
        swipe_container.setOnSwipeRefreshListener(this);
        swipe_container.setHeaderViewBackgroundColor(activity.getResources().getColor(R.color.divider_line_color));

        initHistoryList();

        initHeadView();

        initFooterView();

        include_progress_bar = itemContentView.findViewById(R.id.include_progress_bar);
        include_progress_bar.setVisibility(View.GONE);
        InitView.instance().initProgressBar(activity, include_progress_bar);

        include_no_data = itemContentView.findViewById(R.id.include_no_data);
        include_no_data.setVisibility(View.GONE);

        include_no_net = itemContentView.findViewById(R.id.include_no_net);
        include_no_net.setVisibility(View.GONE);
        include_no_net.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                updateData();
            }
        });

    }

    private void initHeadView() {
        View headView = LayoutInflater.from(activity).inflate(R.layout.head_device_detail, rlv_history_list, false);
        mTvfault = (TextView) headView.findViewById(R.id.tv_fault);
        mTv_fault_des = (TextView) headView.findViewById(R.id.tv_fault_des);
        initDeviceInfoView(headView);
        initChartView(headView);

        deviceErrorlAdapter.setHeaderView(headView);
    }

    private void initDeviceInfoView(View headView) {
        ll_device_info = headView.findViewById(R.id.ll_device_info);
        iv_device_img = headView.findViewById(R.id.iv_device_img);
        tv_device_title = headView.findViewById(R.id.tv_device_title);
        tv_device_flag = headView.findViewById(R.id.tv_device_flag);
        tv_device_flag_1 = headView.findViewById(R.id.tv_device_flag_1);
        iv_icon_video = headView.findViewById(R.id.iv_icon_video);
        iv_device_location = headView.findViewById(R.id.iv_device_location);
        tv_device_location = headView.findViewById(R.id.tv_device_location);
        tv_device_id = headView.findViewById(R.id.tv_device_id);
        tv_device_type = headView.findViewById(R.id.tv_device_type);
        ll_data_history = headView.findViewById(R.id.ll_data_history);
    }

    private void initChartView(View headView) {
        ll_data_chart = headView.findViewById(R.id.ll_data_chart);
        iv_chart_img = headView.findViewById(R.id.iv_chart_img);
        tv_chart_title = headView.findViewById(R.id.tv_chart_title);
        iv_data_time_img = headView.findViewById(R.id.iv_data_time_img);
        tv_data_time = headView.findViewById(R.id.tv_data_time);
        initLineChartList(headView);
    }

    private void initLineChartList(View headView) {
        rlv_chart_list = headView.findViewById(R.id.rlv_chart_list);
        llm_chart = new LinearLayoutManager(activity);
        llm_chart.setOrientation(RecyclerView.VERTICAL);
        rlv_chart_list.setLayoutManager(llm_chart);
        homeStatisticAdapter = new HomeStatisticAdapter(activity);
        homeStatisticAdapter.setDetail(true);
        rlv_chart_list.setAdapter(homeStatisticAdapter);
    }

    private void initHistoryList() {
        rlv_history_list = itemContentView.findViewById(R.id.rlv_history_list);
        linearLayoutManager = new LinearLayoutManager(activity);
        rlv_history_list.setLayoutManager(linearLayoutManager);
        deviceErrorlAdapter = new DeviceErrorAdapter(activity);
        rlv_history_list.setAdapter(deviceErrorlAdapter);

        rlv_history_list.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE
                        && lastVisibleItem + 1 == deviceErrorlAdapter.getItemCount()) {
                    bottomLoadMore();
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
            }
        });
    }

    private void initFooterView() {
        footerView = LayoutInflater.from(activity).inflate(R.layout.item_recyclerview_footer, rlv_history_list, false);
        ll_recycler_footer = footerView.findViewById(R.id.ll_recycler_footer);
        ll_recycler_footer.setVisibility(View.GONE);
        rl_no_more_data = footerView.findViewById(R.id.rl_no_more_data);
        rl_no_more_data.setVisibility(View.GONE);
        deviceErrorlAdapter.setFooterView(footerView);
    }

    private void bottomLoadMore(){
        if (include_no_net.isShown() || include_no_data.isShown()
                || isNoMoreData || !isListLoadOver){
            return;
        }
        setFooterStyle(1);
        initDetailYiChangHttpHelper();
    }

    private void initHttpHelper() {
        initDetailHttpHelper();
    }

    /**
     * 0不显示 1正在加载中 2无更多数据
     * @param style
     */
    private void setFooterStyle(int style){
        switch (style){
            case 1:
                footerView.setVisibility(View.VISIBLE);
                ll_recycler_footer.setVisibility(View.VISIBLE);
                rl_no_more_data.setVisibility(View.GONE);
                break;
            case 2:
                footerView.setVisibility(View.VISIBLE);
                ll_recycler_footer.setVisibility(View.GONE);
                rl_no_more_data.setVisibility(View.VISIBLE);
                isNoMoreData = true;
                break;
            default:
                footerView.setVisibility(View.GONE);
                break;
        }
    }

    /**
     * 获取列表
     */
    private void initDetailHttpHelper() {
        if (Utils.hasNetwork(activity)){
            include_no_net.setVisibility(View.GONE);
        }else {
            include_no_net.setVisibility(View.VISIBLE);
            return;
        }
        include_progress_bar.setVisibility(View.VISIBLE);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("equId", equId);

        HashMap<String, String> url_params = new HashMap<>();
        url_params.put(ConstData.JSONOBJECT, JSONUtil.mapToJSonStr(hashMap));
        HttpHelper homeListHttpHelper = new BaoJingListHttpHelper(activity, Url.DEVICE_DETAIL_URL,
                BAOJING_DETAIL_REQUEST_WHAT, handler, true, url_params);

        homeListHttpHelper.setParseJsonData(new BaoJingParseJsonData());
        homeListHttpHelper.getHttpRequest(true);
    }

    /**
     * 获取列表
     */
    private void initDetailJianCeHttpHelper() {
        if (Utils.hasNetwork(activity)){
            include_no_net.setVisibility(View.GONE);
        }else {
            include_no_net.setVisibility(View.VISIBLE);
            return;
        }
        include_progress_bar.setVisibility(View.VISIBLE);

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("equId", detailHeadModel.getEquId());

        HashMap<String, String> url_params = new HashMap<>();
        url_params.put(ConstData.JSONOBJECT, JSONUtil.mapToJSonStr(hashMap));

        HttpHelper homeListHttpHelper = new BaoJingListHttpHelper(activity, Url.DEVICE_JIANCE_URL,
                JIANCE_DETAIL_REQUEST_WHAT, handler, true, url_params);
        homeListHttpHelper.setParseJsonData(new BaoJingParseJsonData());
        homeListHttpHelper.getHttpRequest(true);
    }

    /**
     * 获取列表
     */
    private void initDetailYiChangHttpHelper() {
        if (Utils.hasNetwork(activity)){
            include_no_net.setVisibility(View.GONE);
        }else {
            include_no_net.setVisibility(View.VISIBLE);
            return;
        }
        isListLoadOver = false;
        include_progress_bar.setVisibility(View.VISIBLE);

        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("equId", detailHeadModel.getEquId());
        hashMap.put(ConstData.COMPANYID, UserInfoModel.getCompandId(activity));
        hashMap.put("equSysId",  detailHeadModel.getEquSysId());
        hashMap.put(ConstData.PAGEINDEX, currentPage + "");
        hashMap.put(ConstData.PAGESIZE, ConstData.PAGE_20);
        String runStatus = SpUtils.getString(App.context, "runStatus");
        if (runStatus!="") {
            // 1报警 2故障 4监管 98预警 6 屏蔽
            if ("1".equals(runStatus)) {
                hashMap.put("runStatus", ConstData.HUOJING_STATUS);

            }else if ("2".equals(runStatus)){
                hashMap.put("runStatus", ConstData.GUZHANG_STATUS);
            }else if ("4".equals(runStatus)){
                hashMap.put("runStatus", ConstData.JIANGUAN_STATUS);
            }else if ("98".equals(runStatus)){
                hashMap.put("runStatus", ConstData.YUJING_STATUS);
            }else if ("6".equals(runStatus)){
                hashMap.put("runStatus", ConstData.PINGBI_STATUS);
            }
        }


        HashMap<String, String> url_params = new HashMap<>();
        url_params.put(ConstData.JSONOBJECT, JSONUtil.mapToJSonStr(hashMap));
        Log.e("TAG111 ",url_params.toString());
        HttpHelper homeListHttpHelper = new BaoJingListHttpHelper(activity, Url.DEVICE_HISTORY_URL,
                YICHANG_DETAIL_REQUEST_WHAT, handler, true, url_params);
        homeListHttpHelper.setParseJsonData(new BaoJingParseJsonData());
        homeListHttpHelper.getHttpRequest(true);
    }

    @Override
    public void onSwipeRefresh() {
        swipe_container.postDelayed(new Runnable() {
            @Override
            public void run() {
                swipe_container.setRefreshing(false);
                updateData();
            }
        }, 2000);
    }

    @Override
    public void onPushDistanceMoreAction(int distance) {

    }

    @Override
    public void onPullEnableMoreAction(boolean enable) {

    }


    private class BaoJingListHttpHelper extends HttpHelper {

        public BaoJingListHttpHelper(BaseActivity activity, String url, int what, Handler handler, boolean isPost, HashMap<String, String> params) {
            super(activity, url, what, handler, isPost, params);
        }
    }

    protected class BaoJingParseJsonData extends ParseJsonData {

        public BaoJingParseJsonData() {
        }

        @Override
        public void analyzeResult(String dataStr, Bundle bundle, int what) {
            try {
            switch (what){
                case BAOJING_DETAIL_REQUEST_WHAT: // 报警详情
                    try {
                        SysBaoJingDeviceDetailModel sysDeviceDetailModel = JSONUtil.jsonObjectToBean(new JSONObject(dataStr), SysBaoJingDeviceDetailModel.class);
                        bundle.putSerializable("detailModel", sysDeviceDetailModel);
                        bundle.putBoolean(REQUEST_OK, true);

                    } catch (JSONException e) {
                        e.printStackTrace();
                        bundle.putBoolean(REQUEST_OK, false);
                        bundle.putString(ERROR_MSG, ANALYZE_ERROR_MSG);
                    }
                    break;
                case JIANCE_DETAIL_REQUEST_WHAT: // 监测情况
                    try {
                        DeviceChartModel deviceChartModel = JSONUtil.jsonObjectToBean(new JSONObject(dataStr), DeviceChartModel.class);
                        bundle.putSerializable("chartList", deviceChartModel);
                        bundle.putBoolean(REQUEST_OK, true);
                    } catch (JSONException e) {
                        e.printStackTrace();
                        bundle.putBoolean(REQUEST_OK, false);
                        bundle.putString(ERROR_MSG, ANALYZE_ERROR_MSG);
                    }
                    break;
                case YICHANG_DETAIL_REQUEST_WHAT:

                        JSONObject jsonObject = new JSONObject(dataStr);
                        ListModel listModel = JSONUtil.jsonObjectToBean(jsonObject, ListModel.class);
                        LinkedList<DetailErrorModel> detailErrorModels = (LinkedList<DetailErrorModel>) JSONUtil.jsonArrayToBeanList(
                                new JSONArray(jsonObject.getString("list")), DetailErrorModel.class);
                        bundle.putSerializable("list", detailErrorModels);
                        bundle.putBoolean(REQUEST_OK, true);
                        try {
                            if (deviceErrorlAdapter.getItemCount() + Integer.parseInt(listModel.getSize())
                                    >= Integer.parseInt(listModel.getTotal())) {
                                isNoMoreData = true;
                            }
                        }catch (Exception e){}

                    break;
                case GET_VIDEO_LIST_WHAT:
                    LinkedList<JianKongDeviceModel> jianKongDeviceModels = (LinkedList<JianKongDeviceModel>) JSONUtil.jsonArrayToBeanList(
                            new JSONArray(dataStr), JianKongDeviceModel.class);
                    bundle.putSerializable("list", jianKongDeviceModels);
                    bundle.putBoolean(REQUEST_OK, true);
                    break;
            }
            } catch (Exception e) {
                e.printStackTrace();
                bundle.putBoolean(REQUEST_OK, false);
                bundle.putString(ERROR_MSG, ANALYZE_ERROR_MSG);
            }
        }
    }

    @Override
    protected void dealWithMyMsgs(Message msg) {
        super.dealWithMyMsgs(msg);
        Bundle bundle = msg.getData();
        if (!bundle.getBoolean(ParseJsonData.REQUEST_OK) ||
                !ParseJsonData.REQUEST_OK_CODE.equals(bundle.getString(ParseJsonData.ERROR_CODE))){
            //ToastUtils.showToast(activity, bundle.getString(ParseJsonData.ERROR_MSG));
            if (msg.what == YICHANG_DETAIL_REQUEST_WHAT) {
                include_progress_bar.setVisibility(View.GONE);
                setFooterStyle(0);
                currentPage--;
                isListLoadOver = true;
            }
            return;
        }
        switch (msg.what){
            case BAOJING_DETAIL_REQUEST_WHAT:
                include_progress_bar.setVisibility(View.GONE);
                detailHeadModel = (SysBaoJingDeviceDetailModel) bundle.getSerializable("detailModel");
                setDetailData();
                break;
            case JIANCE_DETAIL_REQUEST_WHAT:
                DeviceChartModel deviceChartModel = (DeviceChartModel) bundle.getSerializable("chartList");
                if (null != deviceChartModel && "1".equals(deviceChartModel.getIsEnable())){
                    ll_data_chart.setVisibility(View.VISIBLE);
                    homeStatisticAdapter.clear();
                    ArrayList<ChartsModel2> chartsModels = new ArrayList<>();
                    for (int i = 0; i < deviceChartModel.getDataList().size(); i++){
                        DeviceChartItemModel deviceChartItemModel = deviceChartModel.getDataList().get(i);
                        ChartsModel2 chartsModel = new ChartsModel2();
                        chartsModel.setChartTitle(deviceChartItemModel.getName());
                        chartsModel.setUnit(deviceChartItemModel.getUnit());
                        chartsModel.setIsPercentage(deviceChartItemModel.getIsPercentage());
                        List<String> xList = new ArrayList<>();
                        List<String> yList = new ArrayList<>();
                        for (int j = 0; j < deviceChartItemModel.getSeriesList().size(); j++){
                            xList.add(deviceChartItemModel.getSeriesList().get(j).getValue().get(0));
                            yList.add(deviceChartItemModel.getSeriesList().get(j).getValue().get(1));
                        }
                        chartsModel.setxAxis(xList);
                        chartsModel.setyAxis(yList);
                        chartsModels.add(chartsModel);
                    }
                    homeStatisticAdapter.addDatas(chartsModels);
                }else {
                    ll_data_chart.setVisibility(View.GONE);
                }
                break;
            case YICHANG_DETAIL_REQUEST_WHAT:
                isListLoadOver = true;
                include_progress_bar.setVisibility(View.GONE);

                setListData((LinkedList<DetailErrorModel>)bundle.getSerializable("list"));
                break;
            case GET_VIDEO_LIST_WHAT:
                include_progress_bar.setVisibility(View.GONE);
                LinkedList<JianKongDeviceModel> jianKongDeviceModels = (LinkedList<JianKongDeviceModel>) bundle.getSerializable("list");
                if (null != jianKongDeviceModels && jianKongDeviceModels.size() > 0){
                    if (jianKongDeviceModels.size() == 1){
                        Bundle skipToBundle = new Bundle();
                        skipToBundle.putSerializable("JianKongDeviceModel", jianKongDeviceModels.get(0));
                        activity.setClickAction(ConstData.VIDEO, jianKongDeviceModels.get(0).getAccessMode(), "监控设备", null, skipToBundle);
                    }else {
                        Bundle skipToBundle = new Bundle();
                        skipToBundle.putString(ConstData.SHOWTYPPE, ConstData.DEVICEVIDEOLIST);
                        skipToBundle.putSerializable("JianKongDeviceModels", jianKongDeviceModels);
                        activity.setClickAction(ConstData.SHOWFRAG, ConstData.INFOLIST, "监控设备", null, skipToBundle);
                    }
                }
                break;
        }
    }

    private void setListData(LinkedList<DetailErrorModel> list) {
        if (null == list || list.size() == 0){
            if (currentPage == 1){
                deviceErrorlAdapter.clear();
                ll_data_history.setBackground(activity.getResources().getDrawable(R.drawable.shape_white_bg_frame));
            }else {
                setFooterStyle(2);
            }
            return;
        }
        setFooterStyle(0);
        if (currentPage == 1){
            deviceErrorlAdapter.clear();
            ll_data_history.setBackground(activity.getResources().getDrawable(R.drawable.shape_top_white_bg));
        }
        deviceErrorlAdapter.addDatas(list);
        currentPage++;

    }

    private void setDetailData() {
        // 详情
        if (null == detailHeadModel){
            ll_device_info.setVisibility(View.GONE);
        }else {
            ll_device_info.setVisibility(View.VISIBLE);
            tv_device_title.setText(detailHeadModel.getName());

            if (!detailHeadModel.getFaultDesc().equals("")) {
                mTvfault.setText(detailHeadModel.getFaultDesc());
            }else {
                mTv_fault_des.setVisibility(View.GONE);
            }

            StringBuilder stringBuilder = new StringBuilder();
            if (!StringUtils.isEmpty(detailHeadModel.getBuildingName())){
                stringBuilder.append(detailHeadModel.getBuildingName());
            }
            if (!StringUtils.isEmpty(detailHeadModel.getFloorName())){
                stringBuilder.append(detailHeadModel.getFloorName());
            }
            if (!StringUtils.isEmpty(detailHeadModel.getAddress())){
                stringBuilder.append(detailHeadModel.getAddress());
            }
            tv_device_location.setText(stringBuilder.toString());

            tv_device_id.setText(detailHeadModel.getEquId());
            tv_device_type.setText(detailHeadModel.getModel());
            if (StringUtils.isEmpty(detailHeadModel.getRunStatus()) || "0".equals(detailHeadModel.getRunStatus())){
                tv_device_flag.setVisibility(View.GONE);
            }else {
                tv_device_flag.setVisibility(View.VISIBLE);
                tv_device_flag.setText(Utils.changeStatusIdToStr(detailHeadModel.getRunStatus()));
                GradientDrawable gradientDrawable = new GradientDrawable();
                gradientDrawable.setColor(Color.parseColor(Utils.changeStatusIdToColor(detailHeadModel.getRunStatus())));
                gradientDrawable.setCornerRadius(Utils.dip2px(activity, 10));
                tv_device_flag.setBackground(gradientDrawable);
            }

            if (StringUtils.isEmpty(detailHeadModel.getEquVideoIds())){
                iv_icon_video.setVisibility(View.GONE);
            }else {
                iv_icon_video.setVisibility(View.VISIBLE);
                iv_icon_video.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // 获取摄像头
                        initVideoDeviceListHttpHelper(detailHeadModel.getEquVideoIds());
                    }
                });
            }

            initDetailJianCeHttpHelper();
            initDetailYiChangHttpHelper();
        }
    }

    /**
     * 设备分类
     */
    private void initVideoDeviceListHttpHelper(String videoIds) {
        if (Utils.hasNetwork(activity)){
            include_no_net.setVisibility(View.GONE);
        }else {
            include_no_net.setVisibility(View.VISIBLE);
            return;
        }
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("id", videoIds);

        HashMap<String, String> url_params = new HashMap<>();
        url_params.put(ConstData.JSONOBJECT, JSONUtil.mapToJSonStr(hashMap));
        HttpHelper homeListHttpHelper = new BaoJingListHttpHelper(activity, Url.DEVICE_VIDEO_LIST_URL,
                GET_VIDEO_LIST_WHAT, handler, true, url_params);
        homeListHttpHelper.setParseJsonData(new BaoJingParseJsonData());
        homeListHttpHelper.getHttpRequest(true);
        include_progress_bar.setVisibility(View.VISIBLE);
    }

    @Override
    public void updateData() {
        super.updateData();
        isNoMoreData = false;
        currentPage = 1;
        initHttpHelper();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        SpUtils.getString(App.context, "runStatus","");
    }
}
